#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int a[111];
int c[111];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while (t--)
    {
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        int ans=0;
        for (int i=0;i<(1<<n);i++)
        {
            for (int j=1;j<=n;j++)
            {
                if (i&(1<<(j-1)))
                {
                    c[j]=1;
                }
                else
                {
                    c[j]=0;
                }
            }
            int sum=0;
            for (int j=1;j<=n;j++)
            {
                for (int k=j-1;k>=1;k--)
                {
                    if (c[j]==c[k]&&a[j]==a[k])
                    {
                        sum+=a[j];
                        break;
                    }
                }
            }
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}
